/*
 * @Company: TWL
 * @Author: xue jian
 * @Email: xuejian@kanzhun.com
 * @Date: 2019-12-17 17:54:22
 */
#include "rocksdb/db.h"
#include <iostream>
#include <map>
#include <vector>

int main() {
    rocksdb::DB* db;
    rocksdb::Options options;
    options.create_if_missing = true;
    std::vector<std::string> column_family_names;
    
    rocksdb::Status status;
    status = rocksdb::DB::ListColumnFamilies(options, "snap", &column_family_names);
    for (auto& name:column_family_names) {
        std::cout<<name<<std::endl;
    }
    std::cout<<"haha"<<std::endl;
    std::vector<rocksdb::ColumnFamilyDescriptor> column_families;
    // column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, rocksdb::ColumnFamilyOptions(options));
    for (size_t i = 0; i != column_family_names.size(); i++) {
        column_families.emplace_back(column_family_names[i], rocksdb::ColumnFamilyOptions(options));
    }
    std::vector<rocksdb::ColumnFamilyHandle*> cfHandles;

    status = rocksdb::DB::Open(options, "snap", column_families, &cfHandles, &db);
    if (!status.ok()) {
        std::cout<<"can't open the rocksdb"<<std::endl;
        exit(true);
    }
    std::map<std::string, rocksdb::ColumnFamilyHandle*> map_handles;
    for (size_t i(0); i<column_family_names.size(); ++i) {
        std::cout<<column_family_names.at(i)<<std::endl;
        map_handles.insert(std::make_pair(column_family_names.at(i), cfHandles.at(i)));
    }
    for (auto& handle:map_handles) {
        std::cout<<handle.first<<std::endl;
    }
    std::string value;
    std::string key("5");
    status = db->Get(rocksdb::ReadOptions(), map_handles.at("hehe"), key, &value);
    if (status.ok()) {
        std::cout<<"get the value ok"<<std::endl;
    }
    std::cout<<value<<std::endl;
    delete db;

}